from __future__ import annotations
from base.observer_pattern import Observer


class LimitBreakAttrsInc:
    def __init__(self, hp_inc: int, fp_inc: int, trp_inc: int, aa_inc: int, avi_inc: int, asw_inc: int):
        """
        突破加成信息中的属性提升信息
        :param hp_inc: 耐久提升
        :param fp_inc: 炮击提升
        :param trp_inc: 雷击提升
        :param aa_inc: 防空提升
        :param avi_inc: 航空提升
        :param asw_inc: 反潜提升
        """
        self._hp_inc = hp_inc
        self._fp_inc = fp_inc
        self._trp_inc = trp_inc
        self._aa_inc = aa_inc
        self._avi_inc = avi_inc
        self._asw_inc = asw_inc

    @property
    def hp_inc(self):
        return self._hp_inc

    @property
    def fp_inc(self):
        return self._fp_inc

    @property
    def trp_inc(self):
        return self._trp_inc

    @property
    def aa_inc(self):
        return self._aa_inc

    @property
    def avi_inc(self):
        return self._avi_inc

    @property
    def asw_inc(self):
        return self._asw_inc


class LimitBreakPromotion:
    def __init__(self, attrs_inc: LimitBreakAttrsInc = None):
        """
        突破加成信息, 存储某一级突破的加成信息
        :param attrs_inc: 属性提升信息
        """
        self._attrs_inc = attrs_inc
        #TODO 装备槽加成
        #TODO 技能加成

    @property
    def hp_inc(self):
        return self._attrs_inc.hp_inc

    @property
    def fp_inc(self):
        return self._attrs_inc.fp_inc

    @property
    def trp_inc(self):
        return self._attrs_inc.trp_inc

    @property
    def aa_inc(self):
        return self._attrs_inc.aa_inc

    @property
    def avi_inc(self):
        return self._attrs_inc.avi_inc

    @property
    def asw_inc(self):
        return self._attrs_inc.asw_inc


class LimitBreak(Observer):
    def update(self, subject):
        self._level = subject.level

    def __init__(self,
                 limit1: LimitBreakPromotion,
                 limit2: LimitBreakPromotion,
                 limit3: LimitBreakPromotion,
                 breakthrough_grade: int = 3):
        """
        舰船突破信息, 存储舰船每一级突破的加成, 以及当前突破等级和所有突破的总加成
        :param limit1: 1破加成信息
        :param limit2: 2破加成信息
        :param limit3: 3破加成信息
        :param breakthrough_grade: 舰船突破等级
        """
        self._limit1 = limit1
        self._limit2 = limit2
        self._limit3 = limit3
        self._level = 100
        self._breakthrough_grade = breakthrough_grade

    @property
    def breakthrough_grade(self):
        """获取突破等级"""
        return self._breakthrough_grade

    @breakthrough_grade.setter
    def breakthrough_grade(self, value: int):
        self._breakthrough_grade = max(0, min(value, 3))

    @property
    def limit1(self):
        return self._limit1

    @property
    def limit2(self):
        return self._limit2

    @property
    def limit3(self):
        return self._limit3

    @property
    def attrs_inc(self) -> LimitBreakAttrsInc:
        """根据突破等级和突破信息计算实际提升的属性值"""
        lst = [0, 0, 0, 0, 0, 0]
        s = ['hp', 'fp', 'trp', 'aa', 'avi', 'asw']
        for i in range(self._breakthrough_grade):
            for j in range(len(lst)):
                lst[j] += getattr(getattr(self, f'limit{i + 1}'), f'{s[j]}_inc')
        return LimitBreakAttrsInc(*tuple(lst))

    #TODO 获取当前突破等级的总加成
